"""
Problem 46: https://projecteuler.net/problem=46

It was proposed by Christian Goldbach that every odd composite number can be
written as the sum of a prime and twice a square.

9 = 7 + 2 × 12
15 = 7 + 2 × 22
21 = 3 + 2 × 32
25 = 7 + 2 × 32
27 = 19 + 2 × 22
33 = 31 + 2 × 12

It turns out that the conjecture was false.

What is the smallest odd composite that cannot be written as the sum of a
prime and twice a square?
"""

# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/5/15
'''

N = 10001
Primes = [True]*N
Primes[0] = False
Primes[1] = False
for i in range(2, N):
    for k in range(i, (N-1)//i+1):
        Primes[i*k] = False


def solution() -> int:
    '''
    n = m + 2k^2
    '''
    n = 3
    flag = True
    while n < N:
        if not Primes[n]:
            flag = False
            m = 2
            while m < n:
                if Primes[m]:
                    k = ((n-m)/2)**0.5
                    if k == int(k):
                        flag = True
                        print(n, m, int(k))  # 5775 157 53
                if flag:
                    break
                m += 1
        if not flag:
            return n
        n += 2
    print('do not find')
    return None


if __name__ == "__main__":
    import doctest
    doctest.testmod(verbose=False)

    print(solution())
    # 5777
